package main

import (
	"fmt"
	"math"
	"strconv"
)

//#link: https://leetcode-cn.com/problems/smallest-good-base/
func main() {
	n := "13"
	fmt.Println(smallestGoodBase(n))
}

func smallestGoodBase(n string) string {
	atoi, _ := strconv.Atoi(n)
	for m := 59; m > 1; m-- {
		k := int(math.Pow(float64(atoi), 1.0/float64(m)))
		if k <= 1 {
			continue
		}
		s := 0
		for i := 0; i <= m; i++ {
			s = s*int(k) + 1
		}
		if s == atoi {
			return strconv.Itoa(int(k))
		}
	}
	return strconv.Itoa(atoi - 1)
}
